package com.sinosoft.tcmemr.control;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sinosoft.tcmemr.service.PatientService;


@Controller
@RequestMapping("/")
public class LoginController {
	
	@Resource
	private PatientService patientService;

	/**
	 * 默认页面
	 * 
	 * @return
	 */
	@RequestMapping(method = RequestMethod.GET)
	public String index(Model model,HttpServletRequest request) {
		///model.addAttribute("Username", "中医馆1");
		
		/*String strUserName = request.getParameter("username");
		String strPassword = request.getParameter("password");
		
		if ( StringUtil.isBlank(strUserName) || StringUtil.isBlank(strPassword))
			return "app/loginfail";
		try {
			if ( !userService.checkUserPassword(ZYEMRConstants.ZYEMRAID, strUserName, strPassword) )
				return "app/loginfail";
		} catch (Exception e) {
				return "app/loginfail";	
		}*/
		return "app/index";
		
	}
	
	@RequestMapping(value = "login",method = RequestMethod.POST)
	@ResponseBody
	public String login(HttpServletRequest request) {
		String strCallMethod = request.getParameter("jsonpCallback");
		System.out.println("#strCallMethod:"+ strCallMethod);
		System.out.println("#patientId:"+ request.getParameter("patientId"));
		System.out.println("#doctorId:"+ request.getParameter("doctorId"));
		String strUrl = "/ZYEMR/";
		String returnData = "[{openURL:'/ZYEMR/'}]";
		String strReturn = strCallMethod + "(" + returnData + ")";
		//String[] returnData = new String[]{strUrl};
		return strReturn;
	}
	
	/*@RequestMapping(value = "login",method = RequestMethod.POST)
	@ResponseBody
	public ResponseData login(HisData hisdata) {
		System.out.println("#patientId:"+ hisdata.getPatientId());
		System.out.println("#doctorId:"+ hisdata.getDoctorId());
		String strUrl = "/ZYEMR/";
		//String[] returnData = new String[]{strUrl};
		return new ResponseData(true,strUrl);
	}*/
	
	@RequestMapping(value = "his")
	public String hisIndex() {

		return "app/HisIndex";
		
	}
	
	@RequestMapping(value = "pcaseView", method = RequestMethod.GET)
	public String viewPatientCase() {
		///System.out.println("#method:"+ RequestMethod.GET);patientCaseWrite.jsp
		return "tcmemr/pcaseView";
	}
	
	@RequestMapping(value = "pcaseWrite", method = RequestMethod.GET)
	public String writePatientCase(HttpServletRequest request) {
		
		System.out.println("#PatientID:"+ request.getParameter("PatientID"));
		
		return "tcmemr/pcaseWrite";
	}

	/**
	 * 登录页面
	 * 
	 * @return
	 */
	/*@RequestMapping(value = "login", method = RequestMethod.GET)
	public String login() {
		if (SecurityUtil.isLogin()) {
			return "redirect:/";
		}
		return "app/login";
	}

	@RequestMapping(value = "login", method = RequestMethod.POST)
	public String fail(
			@RequestParam(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM) String userName,
			Model model) {
		model.addAttribute(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM,
				userName);
		return "app/login";
	}

	@RequestMapping(value = "logout", method = RequestMethod.POST)
	@ResponseBody
	public String logout() {
		Subject subject = SecurityUtils.getSubject();
		subject.logout();
		return "success";
	}
*/
	
}
